const isDigit = function (c) {
    if (c >= '0' && c <= '9') {
        return true;
    } else {
        return false;
    }
};
/**
 * 单调栈
 * @param {*} str 
 * @returns 
 */
function stackStr(str = "") {
    let nums = [];
    let strs = [];
    let res = "";
    let mult = 0;
    let i = 0;
    while (i < str.length) {
        if (isDigit(str[i])) {
            mult = mult * 10 + Number(str[i]);
        } else if (isChar(str[i])) {
            res = res + str[i];
        } else if (str[i] === '[') {
            nums.push(mult);
            mult = 0;
            strs.push(res);
            res = "";
        } else {
            let times = nums.pop();
            let prestr = strs.pop();
            let curstr = "";
            for (let j = 0; j < times; j++) {
                curstr += res;
            }
            res = prestr + curstr; 
            // 搞明白了，将第一次前面得到的结果放到res中，
            // 当遇到[的时候，再入栈，
            // strs.pop();2[acc3[d]4[yy]]3[ab]
            /**
             * nums = [3];
             * strs = ['ab'];
             * res = "accaccab";
             */
        }
        i++;
    }
    return res;
}